#include "smart_pwm.h"
#include "hal_spi.h"
static whole_led_data led_data_tx_test; /*测试发送结构体*/
static whole_led_data led_data_rx_test;	/*spi回读结构体*/
static led_control_information led_control_information_now;	/*灯控制结构体*/
static Lock_control Lock_control_func ; 					/*车辆上锁功能逻辑控制结构体*/
static UnLock_control UnLock_control_func ; 				/*车辆解锁功能逻辑控制结构体*/
static Charging_control Charging_control_func;				/*充电模式控制结构体*/
static Left_Right Left_Right_func;							/*左右转向灯效次数结构体*/
/*
 * 函数介绍: LED的led_control_information初始化
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void led_control_init(void)
{
	uint16_t i = 0;
	/*初始化灯条的功能*/
	led_control_information_now.Light_effect_now = LIGHT_EFFECT_SIGNAL_MAX;
	/*初始化灯的亮度变化值*/
	led_control_information_now.Brightness_control_now = BRIGHTNESS_CONTROL_SIGNAL_MAX;
	/*初始化灯的亮度*/
	led_control_information_now.Led_Dim_upperlimit_now = RGB_PWM_CLOSE;
	/*初始化灯的RGB-PWM*/
	led_control_information_now.Led_pwm_now.R_PWM = RGB_PWM_CLOSE;
	led_control_information_now.Led_pwm_now.G_PWM = RGB_PWM_CLOSE;
	led_control_information_now.Led_pwm_now.B_PWM = RGB_PWM_CLOSE;
	/*初始化Smart数据*/
	memcpy(led_control_information_now.whole_led_data_now.Smart_control_data, RGB_PWM_CLOSE, NUMBER_LIGHT_BYTES);
	/*初始化每个灯的标志位*/
	for (i = 0; i < LED_NUMBER; i++)
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Flag_bit = LED_FLAG_BIT;
	}
	/*初始化Smart数据的起始信号*/
	led_control_information_now.whole_led_data_now.sig.Start_signal = STARTING_SIGNAL_ALL_0;
	/*初始化Smart数据的结束信号*/
	led_control_information_now.whole_led_data_now.sig.End_signal = END_SIGNAL_ALL_1;
	/*清除结构体数据*/
	Clear_structural_data();
}

/*
 * 函数介绍: 清除结构体数据
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Clear_structural_data(void)
{
	/*初始化解锁控制结构体*/
	memcpy(UnLock_control_func, RGB_PWM_CLOSE, sizeof(UnLock_control_func));
	/*初始化上锁控制结构体*/
	memcpy(Lock_control_func, RGB_PWM_CLOSE, sizeof(Lock_control_func));
	/*清除左转模式次数*/
	Left_Right_func.Left_Number = 0;
	/*清除右转模式次数*/
	Left_Right_func.Right_Number = 0;
	/*清除上锁模式循环次数*/
	Lock_control_func.Number_cycles = 0;
	/*清除解锁模式循环次数*/
	UnLock_control_func.Number_cycles = 0;
	/*清除颜色*/
	close_smart_pwm();
}


/*
 * 函数介绍: 解锁模式第一阶段灯条状态，从中间往右亮灯方向——>>>>
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_ONE_PHASE_right(void)
{
	int16_t i = 0;
	uint16_t j = 0;
	led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+UnLock_control_func.Middle_Right].Dim = \
	led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
	led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+UnLock_control_func.Middle_Right].Red_PWM = \
	led_control_information_now.Led_pwm_now.R_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+UnLock_control_func.Middle_Right].Green_PWM = \
	led_control_information_now.Led_pwm_now.G_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+UnLock_control_func.Middle_Right].Blue_PWM = \
	led_control_information_now.Led_pwm_now.B_PWM;

	if (LOCK_GRADIENT_NUMBER > UnLock_control_func.Middle_Right )/*一阶段亮度变化前几颗灯*/
	{
		/*亮度变化前几颗灯*/
		if (0 == UnLock_control_func.Middle_Right)/*中间往右第一颗灯*/
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (LOCK_GRADIENT_NUMBER)*BRIGHTNESS_VARIATION_VALUE;
		}else{
			for (i = UnLock_control_func.Middle_Right; i >= 0 ; i--)
			{
				led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
				(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (i+1)*BRIGHTNESS_VARIATION_VALUE;/*最高那颗灯亮度最低*/
			}	
		}
	}
	/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑*/
	else if (UnLock_control_func.Middle_Right >= LOCK_GRADIENT_NUMBER && \
			UnLock_control_func.Middle_Right < (LOCK_NUMBER_LIGHTS_MAX-LOCK_GRADIENT_NUMBER))
	{
		/*亮度变化前几颗灯*/
		j = (UnLock_control_func.Middle_Right-LOCK_GRADIENT_NUMBER);
		for (i = UnLock_control_func.Middle_Right; i >= j ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(UnLock_control_func.Middle_Right-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		for ( i ; i >= 0 ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
	}else{/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑+后几颗灯亮度变化*/
		/*亮度变化前几颗灯*/
		for (i = UnLock_control_func.Middle_Right; i >= (UnLock_control_func.Middle_Right-LOCK_GRADIENT_NUMBER) ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(UnLock_control_func.Middle_Right-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		j = (UnLock_control_func.Middle_Right - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER));
		for ( i; i >= j; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
		/*亮度变化后几颗灯*/
		for ( j = 0; j <= (UnLock_control_func.Middle_Right - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER)); j++)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i+1)].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (j+1)*BRIGHTNESS_VARIATION_VALUE;
			i--;
		}
		
	}
	UnLock_control_func.Middle_Right++;
}

/*
 * 函数介绍: 上锁模式第一阶段灯条状态，从左往右亮灯方向——>>>>
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_ONE_PHASE_right(void)
{
	int16_t i = 0;
	uint16_t j = 0;
	led_control_information_now.whole_led_data_now.sig.Smt_led[Lock_control_func.Right_retract_ceiling_light].Dim = \
	led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
	led_control_information_now.whole_led_data_now.sig.Smt_led[Lock_control_func.Right_retract_ceiling_light].Red_PWM = \
	led_control_information_now.Led_pwm_now.R_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[Lock_control_func.Right_retract_ceiling_light].Green_PWM = \
	led_control_information_now.Led_pwm_now.G_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[Lock_control_func.Right_retract_ceiling_light].Blue_PWM = \
	led_control_information_now.Led_pwm_now.B_PWM;

	if (LOCK_GRADIENT_NUMBER > Lock_control_func.Right_retract_ceiling_light )/*一阶段亮度变化前几颗灯*/
	{
		/*亮度变化前几颗灯*/
		if (0 == Lock_control_func.Right_retract_ceiling_light)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[0].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (LOCK_GRADIENT_NUMBER)*BRIGHTNESS_VARIATION_VALUE;
		}else{
			for (i = Lock_control_func.Right_retract_ceiling_light; i >= 0 ; i--)
			{
				led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
				(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (i+1)*BRIGHTNESS_VARIATION_VALUE;
			}	
		}
	}
	/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑*/
	else if (Lock_control_func.Right_retract_ceiling_light >= LOCK_GRADIENT_NUMBER && \
			Lock_control_func.Right_retract_ceiling_light < (LOCK_NUMBER_LIGHTS_MAX-LOCK_GRADIENT_NUMBER))
	{
		/*亮度变化前几颗灯*/
		j = (Lock_control_func.Right_retract_ceiling_light-LOCK_GRADIENT_NUMBER);
		for (i = Lock_control_func.Right_retract_ceiling_light; i >= j ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(Lock_control_func.Right_retract_ceiling_light-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		for ( i ; i >= 0 ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
	}else{/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑+后几颗灯亮度变化*/
		/*亮度变化前几颗灯*/
		for (i = Lock_control_func.Right_retract_ceiling_light; i >= (Lock_control_func.Right_retract_ceiling_light-LOCK_GRADIENT_NUMBER) ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(Lock_control_func.Right_retract_ceiling_light-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		j = (Lock_control_func.Right_retract_ceiling_light - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER));
		for ( i; i >= j; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
		/*亮度变化后几颗灯*/
		for ( j = 0; j <= (Lock_control_func.Right_retract_ceiling_light - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER)); j++)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (j+1)*BRIGHTNESS_VARIATION_VALUE;
			i--;
		}
		
	}
	Lock_control_func.Right_retract_ceiling_light++;
}

/*
 * 函数介绍: 解锁模式第一阶段灯条状态，从中间往左亮灯方向 《《《《《----- 一阶段又分三个小阶段
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_ONE_PHASE_left(void)
{
	int16_t i = 0;
	uint16_t j = 0;
	led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-UnLock_control_func.Middle_Left].Dim = \
	led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
	led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-UnLock_control_func.Middle_Left].Red_PWM = \
	led_control_information_now.Led_pwm_now.R_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-UnLock_control_func.Middle_Left].Green_PWM = \
	led_control_information_now.Led_pwm_now.G_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-UnLock_control_func.Middle_Left].Blue_PWM = \
	led_control_information_now.Led_pwm_now.B_PWM;

	if (LOCK_GRADIENT_NUMBER > UnLock_control_func.Middle_Left )/*一阶段亮度变化前几颗灯*/
	{
		/*亮度变化前几颗灯*/
		if (0 == UnLock_control_func.Middle_Left)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (LOCK_GRADIENT_NUMBER)*BRIGHTNESS_VARIATION_VALUE;
		}else{
			for (i = UnLock_control_func.Middle_Left; i >= 0 ; i--)
			{
				led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-i].Dim = \
				(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (i+1)*BRIGHTNESS_VARIATION_VALUE;
			}
		}
	}
	/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑*/
	else if (UnLock_control_func.Middle_Left >= LOCK_GRADIENT_NUMBER && \
	UnLock_control_func.Middle_Left < (LOCK_NUMBER_LIGHTS_MAX-LOCK_GRADIENT_NUMBER))
	{
		/*亮度变化前几颗灯*/
		j = (UnLock_control_func.Middle_Left-LOCK_GRADIENT_NUMBER);
		for (i = UnLock_control_func.Middle_Left; i >= j ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(UnLock_control_func.Middle_Left-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		for ( i ; i >= 0 ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
	}else{/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑+后几颗灯亮度变化*/
		/*亮度变化前几颗灯*/
		for (i = UnLock_control_func.Middle_Left; i >= (UnLock_control_func.Middle_Left-LOCK_GRADIENT_NUMBER) ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(UnLock_control_func.Middle_Left-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		j = (UnLock_control_func.Middle_Left - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER));
		for ( i; i >= j; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
		/*亮度变化后几颗灯*/
		for ( j = 0; j <= (UnLock_control_func.Middle_Left - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER)); j++)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(CRITICAL_BEAD_POSITION&0xff)-1-(i+1)].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (j+1)*BRIGHTNESS_VARIATION_VALUE;
			i--;
		}
		
	}
	UnLock_control_func.Middle_Left++;
}

/*
 * 函数介绍: 上锁模式第一阶段灯条状态，从右往左亮灯方向 《《《《《----- 一阶段又分三个小阶段
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_ONE_PHASE_left(void)
{
	int16_t i = 0;
	uint16_t j = 0;
	led_control_information_now.whole_led_data_now.sig.Smt_led[LED_NUMBER-Lock_control_func.Left_retract_ceiling_light-1].Dim = \
	led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
	led_control_information_now.whole_led_data_now.sig.Smt_led[LED_NUMBER-Lock_control_func.Left_retract_ceiling_light-1].Red_PWM = \
	led_control_information_now.Led_pwm_now.R_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[LED_NUMBER-Lock_control_func.Left_retract_ceiling_light-1].Green_PWM = \
	led_control_information_now.Led_pwm_now.G_PWM;
	led_control_information_now.whole_led_data_now.sig.Smt_led[LED_NUMBER-Lock_control_func.Left_retract_ceiling_light-1].Blue_PWM = \
	led_control_information_now.Led_pwm_now.B_PWM;

	if (LOCK_GRADIENT_NUMBER > Lock_control_func.Left_retract_ceiling_light )/*一阶段亮度变化前几颗灯*/
	{
		/*亮度变化前几颗灯*/
		if (0 == Lock_control_func.Left_retract_ceiling_light)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (LOCK_GRADIENT_NUMBER)*BRIGHTNESS_VARIATION_VALUE;
		}else{
			for (i = Lock_control_func.Left_retract_ceiling_light; i >= 0 ; i--)
			{
				led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
				(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (i+1)*BRIGHTNESS_VARIATION_VALUE;
			}
		}
	}
	/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑*/
	else if (Lock_control_func.Left_retract_ceiling_light >= LOCK_GRADIENT_NUMBER && \
	Lock_control_func.Left_retract_ceiling_light < (LOCK_NUMBER_LIGHTS_MAX-LOCK_GRADIENT_NUMBER))
	{
		/*亮度变化前几颗灯*/
		j = (Lock_control_func.Left_retract_ceiling_light-LOCK_GRADIENT_NUMBER);
		for (i = Lock_control_func.Left_retract_ceiling_light; i >= j ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(Lock_control_func.Left_retract_ceiling_light-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		for ( i ; i >= 0 ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
	}else{/*一阶段亮度变化前几颗灯+中间亮度不变的几颗灯逻辑+后几颗灯亮度变化*/
		/*亮度变化前几颗灯*/
		for (i = Lock_control_func.Left_retract_ceiling_light; i >= (Lock_control_func.Left_retract_ceiling_light-LOCK_GRADIENT_NUMBER) ; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(i-(Lock_control_func.Left_retract_ceiling_light-LOCK_GRADIENT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;
		}
		/*中间亮度不变的灯*/
		j = (Lock_control_func.Left_retract_ceiling_light - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER));
		for ( i; i >= j; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
			led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		}	
		/*亮度变化后几颗灯*/
		for ( j = 0; j <= (Lock_control_func.Left_retract_ceiling_light - (LOCK_NUMBER_LIGHTS_MAX - LOCK_GRADIENT_NUMBER)); j++)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i+1)].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - (j+1)*BRIGHTNESS_VARIATION_VALUE;
			i--;
		}
		
	}
	Lock_control_func.Left_retract_ceiling_light++;
}

/*
 * 函数介绍: 解锁模式第二阶段灯条状态，从中间向右流动
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_TWO_PHASE_Right(void)
{
	uint16_t i = 0;
	/*思路为将后一颗灯的值赋值为前一颗灯，就能实现灯的流动效果*/
	if (0 == (UnLock_control_func.Middle_Right - LOCK_NUMBER_LIGHTS_MAX) /* condition */)
	{
		for (i = UnLock_control_func.Middle_Right; i >= 1; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Blue_PWM;
		}
		/*第一颗灯后面没有灯了，需要单独赋值*/
		led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST].Blue_PWM = RGB_PWM_CLOSE;
		UnLock_control_func.Middle_Right += 1;
	}
	else
	{
		for (i = UnLock_control_func.Middle_Right; i >= (UnLock_control_func.Middle_Right - LOCK_NUMBER_LIGHTS_MAX); i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Blue_PWM;
		}
		UnLock_control_func.Middle_Right++;
	}
}

/*
 * 函数介绍: 上锁模式第二阶段灯条状态，从左向右流动
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_TWO_PHASE_Right(void)
{
	uint16_t i = 0;
	/*思路为将后一颗灯的值赋值为前一颗灯，就能实现灯的流动效果*/
	if (0 == (Lock_control_func.Right_retract_ceiling_light - LOCK_NUMBER_LIGHTS_MAX) /* condition */)
	{
		for (i = Lock_control_func.Right_retract_ceiling_light; i >= 1; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Blue_PWM;
		}
		/*第一颗灯后面没有灯了，需要单独赋值*/
		led_control_information_now.whole_led_data_now.sig.Smt_led[0].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[0].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[0].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[0].Blue_PWM = RGB_PWM_CLOSE;
		Lock_control_func.Right_retract_ceiling_light += 1;
	}
	else
	{
		for (i = Lock_control_func.Right_retract_ceiling_light; i >= (Lock_control_func.Right_retract_ceiling_light - LOCK_NUMBER_LIGHTS_MAX); i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Blue_PWM;
		}
		Lock_control_func.Right_retract_ceiling_light++;
	}

}

/*
 * 函数介绍: 解锁模式第二阶段灯条状态，从中间向左流动
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_TWO_PHASE_Left(void)
{
	uint16_t i = 0;
	/*思路为将后一颗灯的值赋值为前一颗灯，就能实现灯的流动效果*/
	if (0 == (UnLock_control_func.Middle_Left - LOCK_NUMBER_LIGHTS_MAX) /* condition */)
	{
		for (i = UnLock_control_func.Middle_Left; i >= 1; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Dim;

			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Red_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Green_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Blue_PWM;
		}
		/*第一颗灯后面没有灯了，需要单独赋值*/
		led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)].Blue_PWM = RGB_PWM_CLOSE;
		UnLock_control_func.Middle_Left += 1;
	}
	else
	{
		for (i = UnLock_control_func.Middle_Left; i >= (UnLock_control_func.Middle_Left - LOCK_NUMBER_LIGHTS_MAX); i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Dim;

			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Red_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Green_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[((CRITICAL_BEAD_POSITION&0xff)-1)-(i-1)].Blue_PWM;
		}
		UnLock_control_func.Middle_Left++;
	}

}

/*
 * 函数介绍: 上锁模式第二阶段灯条状态，从右向左流动
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_TWO_PHASE_Left(void)
{
	uint16_t i = 0;
	/*思路为将后一颗灯的值赋值为前一颗灯，就能实现灯的流动效果*/
	if (0 == (Lock_control_func.Left_retract_ceiling_light - LOCK_NUMBER_LIGHTS_MAX) /* condition */)
	{
		for (i = Lock_control_func.Left_retract_ceiling_light; i >= 1; i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Dim;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Red_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Green_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Blue_PWM;
		}
		/*第一颗灯后面没有灯了，第一次需要单独赋值*/
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Blue_PWM = RGB_PWM_CLOSE;
		Lock_control_func.Left_retract_ceiling_light += 1;
	}
	else
	{
		for (i = Lock_control_func.Left_retract_ceiling_light; i >= (Lock_control_func.Left_retract_ceiling_light - LOCK_NUMBER_LIGHTS_MAX); i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Dim;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Red_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Green_PWM;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)-(i-1)].Blue_PWM;
		}
		Lock_control_func.Left_retract_ceiling_light++;
	}

}

/*
 * 函数介绍: 解锁模式第一阶段灯条状态  第一阶段为从0颗灯亮增长到稳定灯珠数量
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_ONE_PHASE(void)
{
	Unlock_func_ONE_PHASE_left();
	Unlock_func_ONE_PHASE_right();
	if (LOCK_NUMBER_LIGHTS_MAX <= UnLock_control_func.Middle_Left && LOCK_NUMBER_LIGHTS_MAX <= UnLock_control_func.Middle_Right)
	{
		UnLock_control_func.light_stage_unLock = TWO_PHASE;
	}
	else
	{
	}
}

/*
 * 函数介绍: 上锁模式第一阶段灯条状态  第一阶段为从0颗灯亮增长到稳定灯珠数量
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_ONE_PHASE(void)
{
	lock_func_ONE_PHASE_right();
	lock_func_ONE_PHASE_left();
	if (LOCK_NUMBER_LIGHTS_MAX <= Lock_control_func.Right_retract_ceiling_light && \
		LOCK_NUMBER_LIGHTS_MAX <= Lock_control_func.Left_retract_ceiling_light)
	{
		Lock_control_func.light_stage_Lock = TWO_PHASE;
	}
	else
	{
	}
}

/*
 * 函数介绍: 解锁模式第二阶段灯条状态  稳定灯珠数量从中间向两边流动
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_TWO_PHASE(void)
{
	Unlock_func_TWO_PHASE_Left();
	Unlock_func_TWO_PHASE_Right();
	if ( ((CRITICAL_BEAD_POSITION&0xff) <= UnLock_control_func.Middle_Left) && \
		  (CRITICAL_BEAD_POSITION <= UnLock_control_func.Middle_Right) )
	{
		UnLock_control_func.Middle_Left = CRITICAL_BEAD_POSITION;
		UnLock_control_func.Middle_Left_num = LOCK_NUMBER_LIGHTS_MAX;
		UnLock_control_func.Middle_Right = CRITICAL_BEAD_POSITION;
		UnLock_control_func.Middle_Right_num = LOCK_NUMBER_LIGHTS_MAX;
		UnLock_control_func.light_stage_unLock = THREE_PHASE;
	}
	else
	{
	}
}

/*
 * 函数介绍: 上锁模式第二阶段灯条状态  稳定灯珠数量从两边像中间流动
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_TWO_PHASE(void)
{
	lock_func_TWO_PHASE_Right();
	lock_func_TWO_PHASE_Left();
	if ( (CRITICAL_BEAD_POSITION <= Lock_control_func.Right_retract_ceiling_light) && \
		 (CRITICAL_BEAD_POSITION <= Lock_control_func.Left_retract_ceiling_light) )
	{
		Lock_control_func.Right_retract_ceiling_light = CRITICAL_BEAD_POSITION;
		Lock_control_func.Right_Three_Phase_light_num = LOCK_NUMBER_LIGHTS_MAX;
		Lock_control_func.Left_retract_ceiling_light = CRITICAL_BEAD_POSITION;
		Lock_control_func.Left_Three_Phase_light_num = LOCK_NUMBER_LIGHTS_MAX;
		Lock_control_func.light_stage_Lock = THREE_PHASE;
	}
	else
	{
	}
}

/*
 * 函数介绍: 解锁模式第三阶段灯条状态	稳定灯珠数量逐渐熄灭所有灯珠
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Unlock_func_THREE_PHASE(void)
{
	uint16_t i = 0;
	/*点亮的灯只剩下亮度会变化的几颗流水的时进入*/
	/*从中间往右的灯*/																	  
	if (FINAL_NUMBER_LIGHTS >= UnLock_control_func.Middle_Right_num && \
		FINAL_NUMBER_LIGHTS >= UnLock_control_func.Middle_Left_num)/*从中间往左的灯*/		   
	{
		/*中间亮度不变的灯不等于基础亮度后标记完成一次流水效果*/
		/*从中间往右的灯*/																																
		if ((DIM_MAX_VALUE != led_control_information_now.whole_led_data_now.sig.Smt_led[LED_NUMBER-LOCK_GRADIENT_NUMBER-1].Dim) && \
			(DIM_MAX_VALUE != led_control_information_now.whole_led_data_now.sig.Smt_led[LOCK_GRADIENT_NUMBER].Dim))	/*从中间往左的灯*/	
		{
			UnLock_control_func.light_stage_unLock = NO_STAGE;
			UnLock_control_func.Middle_Right = 0;
			UnLock_control_func.Middle_Left = 0;
			UnLock_control_func.Number_cycles++; /*循环次数++*/
		}
		else
		{
		}
	}
	else/*每次去掉一颗中间基础亮度的灯*/
	{
		/*去掉从中间往右的灯的中间基础亮度的灯*/
		for (i = (UnLock_control_func.Middle_Right - UnLock_control_func.Middle_Right_num + LOCK_GRADIENT_NUMBER); \
		     i >= (UnLock_control_func.Middle_Right - UnLock_control_func.Middle_Right_num); i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+i].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[UNLOCK_LED_RIGHT_ST+(i-1)].Blue_PWM;
		}
		UnLock_control_func.Middle_Right_num -= 1;

		/*去掉从中间往左的灯的中间基础亮度的灯*/ 
		for (i = (UnLock_control_func.Middle_Left_num  - LOCK_GRADIENT_NUMBER); \
			 i <= (UnLock_control_func.Middle_Left_num ); i++)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Dim = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Red_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Green_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Blue_PWM = \
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM;
		}
		UnLock_control_func.Middle_Left_num -= 1;
	}
}

/*
 * 函数介绍: 上锁模式第三阶段灯条状态	稳定灯珠数量逐渐熄灭所有灯珠
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void lock_func_THREE_PHASE(void)
{
	uint16_t i = 0;
	/*点亮的灯只剩下亮度会变化的几颗流水的时进入*/
	/*从左往右的灯*/																	  
	if (FINAL_NUMBER_LIGHTS >= Lock_control_func.Right_Three_Phase_light_num && \
		FINAL_NUMBER_LIGHTS >= Lock_control_func.Left_Three_Phase_light_num)/*从右往左的灯*/		   
	{
		/*中间亮度不变的灯不等于基础亮度后标记完成一次流水效果*/
		/*从左往右的灯*/																																
		if ((DIM_MAX_VALUE != led_control_information_now.whole_led_data_now.sig.Smt_led[CRITICAL_BEAD_POSITION - 1-LOCK_GRADIENT_NUMBER].Dim) && \
			(DIM_MAX_VALUE != led_control_information_now.whole_led_data_now.sig.Smt_led[CRITICAL_BEAD_POSITION + 1+LOCK_GRADIENT_NUMBER].Dim))	/*从右往左的灯*/	
		{
			Lock_control_func.light_stage_Lock = NO_STAGE;
			Lock_control_func.Right_retract_ceiling_light = 0;
			Lock_control_func.Left_retract_ceiling_light = 0;
			Lock_control_func.Number_cycles++; /*循环次数++*/
		}
		else
		{
		}
	}
	else/*每次去掉一颗中间基础亮度的灯*/
	{
		/*去掉从左往右的灯的中间基础亮度的灯*/
		for (i = (Lock_control_func.Right_retract_ceiling_light - Lock_control_func.Right_Three_Phase_light_num + LOCK_GRADIENT_NUMBER); \
		     i >= (Lock_control_func.Right_retract_ceiling_light - Lock_control_func.Right_Three_Phase_light_num); i--)
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = led_control_information_now.whole_led_data_now.sig.Smt_led[i-1].Blue_PWM;
		}
		Lock_control_func.Right_Three_Phase_light_num -= 1;

		/*去掉从右往左的灯的中间基础亮度的灯*/ 
#if (0 != LED_NUMBER%2)/*灯珠总数为单数*/
		for (i = (Lock_control_func.Left_retract_ceiling_light + Lock_control_func.Left_Three_Phase_light_num - LOCK_GRADIENT_NUMBER); \
			 i <= (Lock_control_func.Left_retract_ceiling_light + Lock_control_func.Left_Three_Phase_light_num); i++)
#else/*灯珠总数为双数*/
		for (i = (Lock_control_func.Left_retract_ceiling_light + Lock_control_func.Left_Three_Phase_light_num - LOCK_GRADIENT_NUMBER-1); \
			 i <= (Lock_control_func.Left_retract_ceiling_light + Lock_control_func.Left_Three_Phase_light_num-1); i++)
#endif
		{
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Dim;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Red_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Green_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Blue_PWM;
		}
		Lock_control_func.Left_Three_Phase_light_num -= 1;
	}
}

/*
 * 函数介绍: 1.OBU发出车辆解锁信号，依次显示白色和蓝色的欢迎动画，由内向两侧示阔，进行两次示阔。
 * 参数:
 * 返回值: {*}
 * 备注:
 */
uint8_t Vehicle_Unlock_func_set_smart_pwm(void)
{
	uint16_t i = 0;
	switch (UnLock_control_func.light_stage_unLock)
	{
		case NO_STAGE:
			UnLock_control_func.light_stage_unLock = ONE_PHASE;
			close_smart_pwm();
			break;
		case ONE_PHASE:
			Unlock_func_ONE_PHASE();
			break;
		case TWO_PHASE:
			Unlock_func_TWO_PHASE();
			break;
		case THREE_PHASE:
			Unlock_func_THREE_PHASE();
			break;
		default:
			break;
	}
	return UnLock_control_func.Number_cycles;
}

/*
 * 函数介绍: 2.OBU发出车辆上锁信号，显示黄色再见动画，由两侧外向内收缩。
 * 参数:
 * 返回值: {*}
 * 备注:
 */
uint8_t Vehicle_lock_func_set_smart_pwm(void)
{
	uint16_t i = 0;
	switch (Lock_control_func.light_stage_Lock)
	{
		case NO_STAGE:
			Lock_control_func.light_stage_Lock = ONE_PHASE;
			close_smart_pwm();
			break;
		case ONE_PHASE:
			lock_func_ONE_PHASE();
			break;
		case TWO_PHASE:
			lock_func_TWO_PHASE();
			break;
		case THREE_PHASE:
			lock_func_THREE_PHASE();
			break;
		default:
			break;
	}
	return Lock_control_func.Number_cycles;
}

/*
 * 函数介绍: 3.OBU发出车辆转向信号，左转：向左流动，循环10次。（蓝色）→→→
 * 参数:
 * 返回值: {*}
 * 备注:
 */
uint8_t Vehicle_turning_left_func_set_smart_pwm(void)
{
	static uint8_t Light_Direction = 0; /*0灯光向左点满所有灯，1灯向左熄灭所有灯*/
	static uint16_t Light_change_lamp = (LED_NUMBER);
	if (10 == Left_Right_func.Left_Number) /*判断循环十次的话清零循环次数*/
	{
		Left_Right_func.Left_Number = 0;
	}
	if (0 == Light_Direction) /*向左点满所有灯*/
	{
		Light_change_lamp--;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
		if (0 == Light_change_lamp) /*所有灯点亮*/
		{
			Light_Direction = 1;			  /*亮灯切换为熄灯*/
			Light_change_lamp = (LED_NUMBER); /*重置灯变化位置*/
		}
		else
		{
		}
	}
	else if (1 == Light_Direction) /*向左熄灭所有灯*/
	{
		Light_change_lamp--;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Blue_PWM = RGB_PWM_CLOSE;
		if (0 == Light_change_lamp) /*所有灯熄灭*/
		{
			Light_Direction = 0;			  /*亮灯切换为熄灯*/
			Light_change_lamp = (LED_NUMBER); /*重置灯变化位置*/
			Left_Right_func.Left_Number++;				  /*更新循环次数*/
		}
		else
		{
		}
	}
	else
	{
	}
	return Left_Right_func.Left_Number;
}

/*
 * 函数介绍: 3.OBU发出车辆转向信号，右转：向右流动，循环10次。（蓝色）→→→
 * 参数:
 * 返回值: {*}
 * 备注:
 */
uint8_t Vehicle_turning_right_func_set_smart_pwm(void)
{
	static uint8_t Light_Direction = 0; /*0灯光向右点满所有灯，1灯向右熄灭所有灯*/
	static uint16_t Light_change_lamp = 0;
	if (10 == Left_Right_func.Right_Number) /*判断循环十次的话清零循环次数*/
	{
		Left_Right_func.Right_Number = 0;
	}
	if (0 == Light_Direction) /*向右点满所有灯*/
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
		Light_change_lamp++;
		if ((LED_NUMBER) == Light_change_lamp) /*所有灯点亮*/
		{
			Light_Direction = 1;   /*亮灯切换为熄灯*/
			Light_change_lamp = 0; /*重置灯变化位置*/
		}
		else
		{
		}
	}
	else if (1 == Light_Direction) /*向右熄灭所有灯*/
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[Light_change_lamp].Blue_PWM = RGB_PWM_CLOSE;
		Light_change_lamp++;
		if ((LED_NUMBER) == Light_change_lamp) /*所有灯熄灭*/
		{
			Light_Direction = 0;   /*亮灯切换为熄灯*/
			Light_change_lamp = 0; /*重置灯变化位置*/
			Left_Right_func.Right_Number++;	   /*更新循环次数*/
		}
		else
		{
		}
	}
	else
	{
	}
	return Left_Right_func.Right_Number;
}

/*
 * 函数介绍: 4.OBU发出车辆预警信号，设置为红色灯光闪烁。收到预警解除信号后，停止闪烁。
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Vehicle_warning_func_set_smart_pwm(void)
{
	uint16_t i = 0;
	for (i = 0; i < LED_NUMBER; i++)
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
	}
}

/*
 * 函数介绍: 设置充电模式下LED的电量百分比
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void charging_set_Battery(uint8_t Battery)
{
	Charging_control_func.Battery_Percentage = Battery;
}

/*
 * 函数介绍: 5.OBU发出车辆充电信号，绿色灯光进行堆栈模式，模拟手机充电显示。
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void Vehicle_charging_func_set_smart_pwm(void)
{
	uint16_t i = 0;
	/*计算电量百分比对应的灯光的临界位置*/
	Charging_control_func.Led_Battery_offset = (float)Charging_control_func.Battery_Percentage * 0.01 * LED_NUMBER;
	/*左边充好电的电量部分灯光赋值*/
	for (i = 0; i < Charging_control_func.Led_Battery_offset; i++)
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
	}
	/*右边未充满电百分比部分动态流水效果赋值*/
	for (i = (Charging_control_func.Led_Battery_offset); i <= (LED_NUMBER-2); i++)
	{/*把临界位置后一个灯赋值给临界位置的灯，最后一个灯再单独赋值，即可实现充电规律流水效果*/
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = \
		led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Dim;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = \
		led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Red_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = \
		led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Green_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = \
		led_control_information_now.whole_led_data_now.sig.Smt_led[i+1].Blue_PWM;
	}

	/*电量为100时，整个灯带常量*/
	if (LED_NUMBER == Charging_control_func.Led_Battery_offset)
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
		led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
	}else
	{/*电量不满时，只赋值最后一个灯，然后把后一个灯的值传给前一个灯，即可实现流水效果*/
		Charging_control_func.Light_led_num ++;
		if (Charging_control_func.Light_led_num <= CHARGING_CHANGES_LIGHT_NUMBER)
		{/*前几颗亮度渐亮的灯*/
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			((CHARGING_CHANGES_LIGHT_NUMBER+1) - Charging_control_func.Light_led_num)*BRIGHTNESS_VARIATION_VALUE;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
		}else if ( (Charging_control_func.Light_led_num > CHARGING_CHANGES_LIGHT_NUMBER) &&\
				(Charging_control_func.Light_led_num <= (CHARGING_CHANGES_NUMBER-CHARGING_CHANGES_LIGHT_NUMBER) ) )
		{/*中间亮度不变的灯*/
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Dim = led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
		}else
		{/*后几颗亮度渐灭的灯*/
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Dim = \
			(led_control_information_now.Led_Dim_upperlimit_now & DIM_MAX_VALUE) - \
			(Charging_control_func.Light_led_num - (CHARGING_CHANGES_NUMBER - CHARGING_CHANGES_LIGHT_NUMBER))*BRIGHTNESS_VARIATION_VALUE;

			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Red_PWM = led_control_information_now.Led_pwm_now.R_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Green_PWM = led_control_information_now.Led_pwm_now.G_PWM;
			led_control_information_now.whole_led_data_now.sig.Smt_led[(LED_NUMBER-1)].Blue_PWM = led_control_information_now.Led_pwm_now.B_PWM;
			/*一组特效完成，前面渐亮中间稳定后面渐灭*/
			if (CHARGING_CHANGES_NUMBER == Charging_control_func.Light_led_num)
			{
				Charging_control_func.Light_led_num = 0;
			}
		}
	}
}

/*
 * 函数介绍: 关闭LED的亮度和RGBPWM值
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void close_smart_pwm(void)
{
	uint8_t i = 0;
	for (i = 0; i < LED_NUMBER; i++)
	{
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Dim = DIM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Red_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Green_PWM = RGB_PWM_CLOSE;
		led_control_information_now.whole_led_data_now.sig.Smt_led[i].Blue_PWM = RGB_PWM_CLOSE;
	}
}

/*
 * 函数介绍: 通过SPI发送smart所有灯数据
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void send_smart(void)
{
	hal_spi_writes(DSPI0, led_control_information_now.whole_led_data_now.Smart_control_data, led_data_rx_test.Smart_control_data, NUMBER_LIGHT_BYTES);
}

/*
 * 函数介绍: 设置当前功能状态
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void st_Light_effect_now(Light_effect effect)
{
	led_control_information_now.Light_effect_now = effect;
}

/*
 * 函数介绍: 返回当前功能状态
 * 参数:
 * 返回值: {*}
 * 备注:
 */
Light_effect rt_Light_effect_now(void)
{
	return led_control_information_now.Light_effect_now;
}

/*
 * 函数介绍: 设置当前亮度调节状态
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void st_Brightness_control_now(Brightness_control control_now)
{
	led_control_information_now.Brightness_control_now = control_now;
}

/*
 * 函数介绍: 返回当前亮度调节状态
 * 参数:
 * 返回值: {*}
 * 备注:
 */
Brightness_control rt_Brightness_control_now(void)
{
	return led_control_information_now.Brightness_control_now;
}

/*
 * 函数介绍: 设置当前颜色亮度上限
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void st_Led_Dim_upperlimit_now(uint8_t Dim_upperlimit)
{
	led_control_information_now.Led_Dim_upperlimit_now = Dim_upperlimit;
}

/*
 * 函数介绍: 返回当前颜色亮度上限
 * 参数:
 * 返回值: {*}
 * 备注:
 */
uint8_t rt_Led_Dim_upperlimit_now(void)
{
	return led_control_information_now.Led_Dim_upperlimit_now;
}

/*
 * 函数介绍: 设置当前LED的三色PWM值
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void st_Led_pwm_now(Led_pwm led_pwm_st)
{
	led_control_information_now.Led_pwm_now.R_PWM = led_pwm_st.R_PWM;
	led_control_information_now.Led_pwm_now.G_PWM = led_pwm_st.G_PWM;
	led_control_information_now.Led_pwm_now.B_PWM = led_pwm_st.B_PWM;
}

/*
 * 函数介绍: 返回当前LED的三色PWM值
 * 参数:
 * 返回值: {*}
 * 备注:
 */
Led_pwm rt_Led_pwm_now(void)
{
	return led_control_information_now.Led_pwm_now;
}

/*
 * 函数介绍: 灯黄光测试函数
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void led_control_test(void)
{
	uint8_t i = 0;
	led_data_tx_test.sig.Start_signal = STARTING_SIGNAL_ALL_0;
	led_data_tx_test.sig.End_signal = END_SIGNAL_ALL_1;
	for (i = 0; i < LED_NUMBER; i++)
	{
		led_data_tx_test.sig.Smt_led[i].Flag_bit = LED_FLAG_BIT;
		led_data_tx_test.sig.Smt_led[i].Dim = 0x1;
		led_data_tx_test.sig.Smt_led[i].Red_PWM = 0xFF;
		led_data_tx_test.sig.Smt_led[i].Green_PWM = 0xFF;
		led_data_tx_test.sig.Smt_led[i].Blue_PWM = 0x0;
	}
	hal_spi_writes(DSPI0, led_data_tx_test.Smart_control_data, led_data_rx_test.Smart_control_data, NUMBER_LIGHT_BYTES);
}
